import request from '@/config/axios'
import {
  IPutPwdReset,

  IUserUpdate
} from './userType';
const userBaseUrl = 'http://localhost:3000/dev-api/users/'

/**
 * 登录
 */
export const login = (data: LoginFormModule): Promise<IResponse> => {
  return request.post({ url: `${userBaseUrl}login`, data })
}

/**
 * 注册
 */
export const register = (data: LoginFormModule): Promise<IResponse> => {
  return request.post({ url: `${userBaseUrl}register`, data })
}

/**
 * 发送验证码
 */
export const email = (data: { user_email: string; }): Promise<IResponse> => {
  return request.post({ url: 'http://localhost:3000/dev-api/email', data })
}


/**
 * 获取用户信息
 */
export const getInfo = () => {
  return request.get({ url: `${userBaseUrl}userInfo` })
}

/**
 * 获取用户信息
 */
export const fetchGetUserInfoById = (id: any) => {
  return request.get({ url: `${userBaseUrl}userId/${id}` })
}

// /**
//  * 修改用户信息
//  */
// export const updateUserInfo = (data: IUserUpdate): Promise<IResponse> => {
//   return request.put({ url: `${userBaseUrl}`, data })
// }

/**
 * 修改密码
 */
export const putPassword = (data: {password: string; email: string; captcha: string; emailCaptcha: string; }) => {
  return request.put({ url: `${userBaseUrl}password`, data })
}


/**
 * 退出登录
 */
export const logout = (): Promise<IResponse> => {
  return request.post({ url: `${userBaseUrl}logout` })
}


// 获取用户列表
export const fetchGetUserList = (params:any): Promise<IResponse> => {
  return request.get({ url: `${userBaseUrl}`, params })
}

/**
 * 重置密码
 */
export const putPwdReset = (data: any) => {
  return request.put({ url: `${userBaseUrl}password-reset`, data })
}
/**
 * 修改人员信息
 */
export const fetchPutUserInfo = (data: any) => {
  return request.put({ url: `${userBaseUrl}userInfo`, data })
}
